package com.greedy;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class Solution19 {
    public List<Integer> partitionLabels(String s) {
        char[] chars = s.toCharArray();
        int[] counts = new int[26];
        for (int i = 0; i < chars.length; i++) {
            counts[chars[i]-'a'] = i;
        }
        List<Integer> res = new ArrayList<>();
        int index = 0;
        int pre = -1;
        for (int i = 0; i < chars.length; i++) {
            index = Math.max(index,counts[chars[i]-'a']);
            if (i == index) {
                res.add(i-pre);
                pre = i;
            }
        }
        return res;
    }
}
